@extends('Admin.layouts.application')
@section('css')
    <link rel="stylesheet" href="/assets/xSystem/vendor/daterangepicker/daterangepicker.css">

@endsection
@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">视频管理列表</strong> /
                    <small>Video management list</small>
                </div>
            </div>

            <hr>
            @include('Admin.layouts._flash')
            <div class="am-g" style="height: 37px;">
                <div class="am-u-sm-12 am-u-md-4">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a type="button" class="am-btn am-btn-success" href="{{route('video.create')}}">
                                <span class="am-icon-plus"></span> 新增视频
                            </a>

                            <a type="button" class="am-btn am-btn-default" id="destroy_checked">
                                <span class="am-icon-trash-o"></span> 删除
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-12">
                    <form class="am-form-inline" role="form" method="get">

                        <div class="am-form-group">
                            <input type="text" name="name" class="am-form-field am-input-sm" placeholder="视频名称"
                                   value="{{ Request::input('name') }}">
                        </div>

                        <div class="am-form-group">
                            <select data-am-selected="{btnStyle: 'secondary', btnSize: 'sm', maxHeight: 360}"
                                    name="video_category_id">
                                <option value="-1">所有分类</option>
                                @foreach($filter_categories as $category)
                                    <option value="{{$category->id}}"
                                            @if($category->id == Request::input('video_category_id')) selected @endif>
                                        {{$category->name}}
                                    </option>
                                @endforeach
                            </select>


                        </div>

                        <div class="am-form-group">
                            <div class="am-btn-group" data-am-button="">
                                <label class="am-btn am-btn-default am-btn-sm am-radius @if(Request::input('is_top') == 1) am-active @endif">

                                    <input type="checkbox" name="is_top" value="1" @if(Request::input('is_top') == 1) checked @endif> 置顶
                                </label>
                                <label class="am-btn am-btn-default am-btn-sm am-radius @if(Request::input('is_recommend') == 1) am-active @endif">
                                    <input type="checkbox" name="is_recommend" value="1" @if(Request::input('is_recommend') == 1) checked @endif> 推荐
                                </label>
                                <label class="am-btn am-btn-default am-btn-sm am-radius @if(Request::input('is_hot') == 1) am-active @endif">
                                    <input type="checkbox" name="is_hot" value="1" @if(Request::input('is_hot') == 1) checked @endif> 热销
                                </label>
                                <label class="am-btn am-btn-default am-btn-sm am-radius @if(Request::input('is_new') == 1) am-active @endif">
                                    <input type="checkbox" name="is_new" value="1" @if(Request::input('is_new') == 1) checked @endif> 新片
                                </label>
                                <label class="am-btn am-btn-default am-btn-sm am-radius @if(Request::input('is_local') == 1) am-active @endif">
                                    <input type="checkbox" name="is_local" value="1" @if(Request::input('is_local') == 1) checked @endif> 本地视频
                                </label>
                            </div>
                        </div>
                        <div  class="am-form-group">
                            <select data-am-selected="{btnSize: 'sm'}" name="is_show" id="">
                                <option value="-1" @if(Request::input('is_show') == '-1') selected @endif>是否显示</option>
                                <option value="1" @if(Request::input('is_show') == '1') selected @endif>是</option>
                                <option value="0" @if(Request::input('is_show') == '0') selected @endif>否</option>
                            </select>
                        </div>

                        <button type="submit" class="am-btn am-btn-default am-btn-sm">查询</button>
                    </form>
                </div>

            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">

                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-check"><input type="checkbox" id="checked"/></th>
                                <th class="table-id">ID</th>
                                <th class="table-thumb">缩略图</th>
                                <th class="table-title">视频名称</th>
                                <th class="table-title">主演</th>
                                <th class="table-title">标题</th>
                                <th class="table-category">所属大类</th>
                                <th class="table-category">所属小类</th>
                                <th class="am-hide-sm-only">显示</th>
                                <th class="am-hide-sm-only">置顶</th>
                                <th class="am-hide-sm-only">热门</th>
                                <th class="am-hide-sm-only">推荐</th>
                                <th class="am-hide-sm-only">新片</th>
                                <th class="am-hide-sm-only">自动更新</th>
                                <th class="table-category">点播次数</th>
                                <th class="table-set">操作</th>

                            </tr>
                            </thead>
                            <tbody>
                            @foreach ($videos as $video)
                                <tr data-id="{{$video->id}}">
                                    <td><input type="checkbox" value="{{$video->id}}" class="checked_id"
                                               name="checked_id[]"/></td>
                                    <td>{{$video->id}}</td>
                                    <td>
                                        @if($video->thumb)<img width="100" height="50" src="{{$video->thumb}}" alt="" class="thumb">@endif
                                    </td>
                                    <td>

                                        {{cut_utf8($video->name,6)}}
                                    </td>
                                    <td>
                                        {{cut_utf8($video->stars,6)}}
                                    </td>

                                    <td>
                                        {{cut_utf8($video->title,5)}}
                                    </td>

                                    <td>{{$video->video_category->name}}</td>
                                    <td>{{$video->genre}}</td>
                                        @if($video->video_category_id == 1 && $video->is_local == 0)
                                            @foreach (array('is_show','is_top','is_hot','is_recommend','is_new','is_episode') as $attr)
                                                <td class="am-hide-sm-only">
                                                    {!! is_something($attr, $video) !!}
                                                </td>
                                            @endforeach
                                        @else
                                            @foreach (array('is_show','is_top','is_hot','is_recommend','is_new','is_episode') as $attr)
                                                @if($attr=="is_episode")
                                                    <td class="am-hide-sm-only">

                                                    </td>
                                                @else
                                                    <td class="am-hide-sm-only">
                                                        {!! is_something($attr, $video) !!}
                                                    </td>
                                                @endif
                                            @endforeach
                                        @endif

                                    <td>
                                        {{$video->num}}
                                    </td>

                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                   href="{{route('video.edit', $video->id)}}">
                                                    <span class="am-icon-pencil-square-o"></span> 编辑
                                                </a>

                                                <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                                   href="{{route('video.destroy', $video->id)}}"
                                                   data-method="delete"
                                                   data-token="{{csrf_token()}}" data-confirm="确认删除吗?">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                        共{{$videos->total()}}条记录
                        <div class="am-cf">
                            <div class="am-fr">
                               {!! $videos->appends(Request::all())->links() !!}
                            </div>
                        </div>
                        <hr/>
                    </form>
                </div>

            </div>
        </div>
        @include('Admin.layouts._footer')

    </div>
@endsection

@section('js')
    <script src="/assets/xSystem/vendor/daterangepicker/moment.js"></script>
    <script src="/assets/xSystem/vendor/moment/locale/zh-cn.js"></script>
    <script src="/assets/xSystem/vendor/daterangepicker/daterangepicker.js"></script>
    <script src="/assets/xSystem/js/daterange_config.js"></script>
    <script>
        //是否...
        $(".is_something").click(function () {
            var _this = $(this);
            var data = {
                id: _this.parents("tr").data('id'),
                attr: _this.data('attr')
            }

            $.ajax({
                type: "PATCH",
                url: "/video/is_something",
                data: data,
                success: function () {
                    _this.toggleClass('am-icon-close am-icon-check');
                }
            });
        });

        //删除所选
        $('#destroy_checked').click(function () {
            var del_video= confirm('确定要删除吗？');
            if(del_video){
                var length = $(".checked_id:checked").length;
                if (length == 0) {
                    alert("您必须至少选中一条!");
                    return false;
                }

                var checked_id = $(".checked_id:checked").serialize();

                $.ajax({
                    type: "DELETE",
                    url: "/video/destroy_checked",
                    data: checked_id,
                    success: function () {
                        location.href = '/video';
                    }
                });
            }
        });

        //排序
        $("input[name='sort_order']").change(function () {
            var data = {
                sort_order: $(this).val(),
                id: $(this).parents("tr").data('id')
            };
            console.log(data);
            $.ajax({
                type: "PATCH",
                url: "/video/sort_order",
                data: data,
            });
        });

    </script>

@endsection





